home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / awe / awe-full.lha / Awe2 / DoNotUseThisSrc / SingleSimMux.cc < prev    next >
C/C++ Source or Header  |  1990-08-08  |  4KB  |  182 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. // 
  3. // Copyright (C) 1988 University of Illinois, Urbana, Illinois
  4. //
  5. // written by Dirk Grunwald (grunwald@cs.uiuc.edu)
  6. //
  7.  
  8. #ifdef __GNUG__
  9. #  pragma implementation
  10. #endif
  11.  
  12. #include "SingleSimMux.h"
  13. #include "AwesimeHeap.h"
  14. #include "Thread.h"
  15. #include "HardwareContextP.h"
  16. #include "TimeSchedulerSplayPQ.h"
  17. #include "ReserveByException.h"
  18. #include <math.h>
  19. #include "Debug.h"
  20.  
  21.  
  22. extern int CpuMuxDebugFlag;
  23.  
  24. SingleSimMux::SingleSimMux(int debug )
  25.     : SimulationMultiplexor(debug), SingleCpuMux(debug)
  26. {
  27.     ThisSimulationMultiplexor = this;
  28.     ThisCpu = this;
  29.     
  30.     SingleCpuMux::allocateLocalEventStructures(0,1);
  31.     pNameTemplate = "SingleSimMux";
  32.     sprintf(nameSpace, "[%s-%d] ", pNameTemplate, SingleCpuMux::iYam);
  33.     pName = nameSpace;
  34.     SingleSimMux::allocateLocalEventStructures(0,1);
  35. }
  36.  
  37. void
  38. SingleSimMux::allocateLocalEventStructures(int, int)
  39. {
  40.     DEBUG_START;
  41.     cerr  << name() << " enter allocateLocalEventStructures\n";
  42.     DEBUG_END;
  43.     myPendingEvents = new TimeSchedulerSplayPQ;
  44. }
  45.  
  46. void
  47. SingleSimMux::allocateEventStructures(int newIYam, int outOf)
  48. {
  49.     
  50.     DEBUG_START;
  51.     
  52.     cerr  << name() << " enter allocateEventStructures\n";
  53.     DEBUG_END;
  54.     
  55.     allocateLocalEventStructures(newIYam, outOf);
  56.     
  57.     //
  58.     // must do this after the local structures get set up so that
  59.     // CpuMultiplexors does not increase until all data structures are
  60.     // in place, otherwise people may poke at them before they're set up.
  61.     //
  62.     
  63.     //CpuMultiplexor::allocateEventStructures(newIYam, outOf);
  64. }
  65.  
  66. void
  67. SingleSimMux::deallocateEventStructures()
  68. {
  69.     
  70.     //    CpuMultiplexor::deallocateEventStructures();
  71.     
  72.     DEBUG_START;
  73.     cerr  << name() << " enter deallocateEventStructures\n";
  74.     DEBUG_END;
  75.     
  76.     delete myPendingEvents;
  77.     myPendingEvents = 0;
  78. }
  79.  
  80. void
  81. SingleSimMux::warmThePot(int)
  82. {
  83.     DEBUG_START;
  84.     cerr  << name() << " enter warmThePot\n";
  85.     DEBUG_END;
  86.     
  87.     SingleCpuMux::warmThePot(1);
  88. }
  89.  
  90. void
  91. SingleSimMux::coolItDown()
  92. {
  93.     DEBUG_START;
  94.     cerr  << name() << " enter coolItDown\n";
  95.     DEBUG_END;
  96.  
  97.     SingleCpuMux::coolItDown();
  98. }
  99.  
  100. void
  101. SingleSimMux::add( Thread * t )
  102. {
  103.     
  104.     DEBUG_START;
  105.     cerr  << name() << " enter SingleSimMux::add\n";
  106.     DEBUG_END;
  107.     
  108.     myPendingEvents->enq( TimeScheduler(t, CurrentSimulatedTime) );
  109. }
  110.  
  111. Thread * SingleSimMux::remove()
  112. {
  113.     DEBUG_START;
  114.     cerr  << name() << " enter SingleSimMux::remove\n";
  115.     DEBUG_END;
  116.     
  117.     if ( *terminated || myPendingEvents -> empty() ) {
  118.     return(0);
  119.     }
  120.     TimeScheduler item = myPendingEvents -> deq();
  121.     CurrentSimulatedTime = item.time();
  122.     return( item.thread() );
  123. }
  124.  
  125. int
  126. SingleSimMux::advanceTime()
  127. {
  128.     assert(0);
  129. }
  130.  
  131. void
  132. SingleSimMux::stirItAround()
  133. {
  134.     DEBUG_START;
  135.     cerr  << name() << " enter SingleSimMux::stirItAround\n";
  136.     DEBUG_END;
  137.     
  138.     for (;;) {
  139.     assert( myCurrentEvents -> isEmpty() );
  140.     
  141.     DEBUG_START;
  142.     cerr  << name() << " Prepare to dispatch task\n";
  143.     DEBUG_END;
  144.     
  145.     if ( myPendingEvents -> empty() ) {
  146.         DEBUG_START;
  147.         cerr  << name() << " myPendingEvents is empty\n";
  148.         DEBUG_END;
  149.         return;
  150.     }
  151.     //
  152.     //    Grab reference to schedule item, and then delete it
  153.     //    to avoid copy overhead
  154.     //
  155.  
  156.     TimeScheduler &item = myPendingEvents -> front();
  157.     DEBUG_START;
  158.     cerr << name() << "itemis " << hex(long(item.thread()));
  159.     cerr << " " << item.time() << "\n";
  160.     DEBUG_END;
  161.     
  162.     CurrentSimulatedTime = item.time();
  163.     currentThread = item.thread();
  164.     myPendingEvents -> del_front();
  165.     
  166.     DEBUG_START;
  167.     cerr << name() << " switch to " << hex(long(currentThread));
  168.     cerr << " at " << CurrentSimulatedTime << "\n";
  169.     cerr.flush();
  170.     DEBUG_END;
  171.     
  172.     systemContext.switchContext(&(currentThread -> pContext));
  173.     raisedBy -> handleException();
  174.     raisedBy = 0;
  175.     }
  176.  
  177.     DEBUG_START;
  178.     cerr  << name() << " exit SingleSimMux::stirItAround\n";
  179.     DEBUG_END;
  180.     
  181. }
  182.